<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #parent {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 200px;
        height: 200px;
        border: 2px solid red;
      }

      #son {
        width: 80px;
        height: 80px;
        border: 2px solid burlywood;
      }
    </style>
  </head>
  <body>
    <div id="parent">
      <div id="son"></div>
    </div>
    <script>
      var parentEle = document.getElementById('parent');
      var sonEle = document.getElementById('son');

      // 绑定单击事件
      parentEle.addEventListener('click', function () {
        console.log('父');
      });
      sonEle.addEventListener('click', function (event) {
        // 阻止事件传播
        event.stopPropagation();
        console.log('子');
      });
    </script>
  </body>
</html>
